// ITI 1120 Winter 2012, Lab 4, Exercise 4-a // Name: Gilbert Arbez, Student# 123456 /** * Requests from the user an integer value. * Calls tha problem solving method to compute N! and * displays the results of the calculation. */ class Lab4Ex4aSol { public static void main (String args[ ]) { // DECLARE VARIABLES/DATA DICTIONARY int n; // number to calulate the factorial int nFact; // n! // PRINT OUT IDENTIFICATION INFORMATION System.out.println("ITI 1120 Winter 2012, Lab 4, Exercise 4-a"); System.out.println("Name: Grace Hoper, Student# 12345678"); System.out.println(); // READ IN GIVENS use our ITI1120 special class for keyboard input System.out.print("Please enter a positive integer to calculate N!: "); n = ITI1120.readInt(); // BODY OF ALGORITHM - Call to the method to solve problem nFact = calculateFact(n); // PRINT OUT RESULTS AND MODIFIEDS System.out.println("The factoriel is "+nFact); } // Problem Solving Method // Description: Calculate n! // Parameters (GIVENS): n - number to calculate factorial. public static int calculateFact(int n) { // DECLARE VARIABLES/DATA DICTIONARY // INTERMEDIATES int count; // count from 1 to N // RESULT int fact; // The factoriel of n // BODY OF ALGORITHM fact = 1; count = 1; while(count <= n) // si n est zéro, fact = 1 { fact = fact * count; count = count+1; } // RETURN RESULT return(fact); } } // Don't remove this brace bracket!